package com.qq.financeSystem.utils;

public class Parse {

    //单独字符串，给金额字符串加，号
    public static String moneyParse(String s) {
        //是否需要
        if (s.length() < 4)
            return s;
        //是否带有小数点
        if (s.contains(".")){
            String temp = "";
            char[] chars = s.toCharArray();
            for (int i = 0; i <s.length() ; i++) {
                if (chars[i] == '.')
                    break;
                temp += chars[i];
            }
            s = temp;
        }
        //格式处理
        StringBuilder builder = new StringBuilder();
        char[] chars = s.toCharArray();
        int count = 0;
        for (int i = s.length() - 1; i >= 0; i--) {
            if (count == 3) {
                builder.append(",");
                count = 0;
            }
            builder.append(chars[i]);
            count++;
        }
        builder.reverse();
        return builder.toString();
    }

    //集合字符串，金额逗号
    /*public static List<String> moneyParse(List<String> list) {

        ArrayList<String> newString = new ArrayList<>();

        for (int i = 0; i < list.size(); i++) {
            StringBuilder builder = new StringBuilder();
            if (list.get(i).equals("0") || list.get(i).length() < 4 ){
                newString.add(list.get(i));
                continue;
            }
            char[] chars = list.get(i).toCharArray();
            int count = 0;

            for (int j = list.get(i).length() - 1; j >= 0; j--) {
                if (count == 3) {
                    builder.append(",");
                    count = 0;
                }
                builder.append(chars[j]);
                count++;
            }

            builder.reverse();
            newString.add(builder.toString());

        }
        return newString;
    }*/

}
